#import "dfhgwhruebvhrheysternideology.h"
#import "dfhgwhruebvhrheyluggagerecorder.h"
#import "dfhgwhruebvhrheyleisureinterference.h"
#import "dfhgwhruebvhrheyoccurrenceadditionalViewController.h"
#import "dfhgwhruebvhrheymaintainlunarViewController.h"
#import "dfhgwhruebvhrheyspecializequeueViewController.h"
@interface dfhgwhruebvhrheyoccurrenceadditionalViewController ()<UIScrollViewDelegate>
@property (nonatomic, strong) dfhgwhruebvhrheymaintainlunarViewController *productVC;
@property (nonatomic, strong) dfhgwhruebvhrheyspecializequeueViewController *collectionVC;
@end
@implementation dfhgwhruebvhrheyoccurrenceadditionalViewController {
	UIView *spaceView;
	UIView *lineIV;
	UIView *topView;
	UIButton *productIssusBtn;
	UIButton *collectionIssueBtn;
	UIScrollView *scrollView;
	UIView *containerView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
	[self loadUI];
}
- (void)loadUI {
    if (self.isRoot) {
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(13, 0, dhgfywegwygeydwdispositionvisualize-26, 44)];
        titleLabel.text = @"FeedBack";
        titleLabel.font = [UIFont semiBold:20];
        titleLabel.textColor = [UIColor whiteColor];
        self.navigationItem.titleView = titleLabel;
    }else {
        self.navigationItem.title = @"FeedBack";
        [self configBackIcon:@"dhgfywegwygeydwcurvereciprocal"];
    }
	self.navigationStyle = dhgfywegwygeydwreciprocaltransport;
	spaceView = [[UIView alloc] init];
	spaceView.backgroundColor = bg_color1.dhgfywegwygeydwlearneddesignate;
	[self.view addSubview:spaceView];
	topView = [[UIView alloc] init];
	topView.backgroundColor = primary_color.dhgfywegwygeydwlearneddesignate;
	[self.view addSubview:topView];
	lineIV = [[UIView alloc] init];
	lineIV.layer.cornerRadius = 1.5;
	lineIV.backgroundColor = second_color.dhgfywegwygeydwlearneddesignate;
	[topView addSubview:lineIV];
	productIssusBtn = [UIButton buttonWithType:UIButtonTypeCustom];
	productIssusBtn.tag = 100;
	productIssusBtn.selected = YES;
	productIssusBtn.layer.cornerRadius = 10;
	productIssusBtn.titleLabel.font = [UIFont regular:15];
	[productIssusBtn setTitle:@"Product Issue" forState:UIControlStateNormal];
	[productIssusBtn setTitleColor:white_color.dhgfywegwygeydwlearneddesignate forState:UIControlStateNormal];
	[productIssusBtn setTitleColor:second_color.dhgfywegwygeydwlearneddesignate forState:UIControlStateSelected];
	[productIssusBtn addTarget:self action:@selector(topBtnsAction:) forControlEvents:UIControlEventTouchUpInside];
	[topView addSubview:productIssusBtn];
	collectionIssueBtn = [UIButton buttonWithType:UIButtonTypeCustom];
	collectionIssueBtn.tag = 101;
	collectionIssueBtn.layer.cornerRadius = 10;
	collectionIssueBtn.titleLabel.font = [UIFont regular:15];
	[collectionIssueBtn setTitle:@"Collection Problems" forState:UIControlStateNormal];
	[collectionIssueBtn setTitleColor:white_color.dhgfywegwygeydwlearneddesignate forState:UIControlStateNormal];
	[collectionIssueBtn setTitleColor:second_color.dhgfywegwygeydwlearneddesignate forState:UIControlStateSelected];
	[collectionIssueBtn addTarget:self action:@selector(topBtnsAction:) forControlEvents:UIControlEventTouchUpInside];
	[topView addSubview:collectionIssueBtn];
	scrollView = [[UIScrollView alloc] init];
	scrollView.pagingEnabled = YES;
	scrollView.bounces = NO;
	scrollView.delegate = self;
	scrollView.showsHorizontalScrollIndicator = NO;
	[self.view addSubview:scrollView];
	containerView = [[UIView alloc] init];
	[scrollView addSubview:containerView];
	__weak typeof(self) weakSelf = self;
	self.productVC = [[dfhgwhruebvhrheymaintainlunarViewController alloc] init];
	[self.productVC submit:^(dfhgwhruebvhrheyleisureinterference * _Nonnull model) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		[strongSelf submit:model];
	}];
	self.collectionVC = [[dfhgwhruebvhrheyspecializequeueViewController alloc] init];
	[self.collectionVC submit:^(dfhgwhruebvhrheyleisureinterference * _Nonnull model) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		[strongSelf submit:model];
	}];
	[self addChildViewController:self.productVC];
	[self addChildViewController:self.collectionVC];
	[containerView addSubview:self.productVC.view];
	[containerView addSubview:self.collectionVC.view];
}
- (void)topBtnsAction:(UIButton *)sender {
	productIssusBtn.selected = NO;
	collectionIssueBtn.selected = NO;
	sender.selected = YES;
	if (sender.tag == 100) {
		[scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
	}else {
		[scrollView setContentOffset:CGPointMake(dhgfywegwygeydwdispositionvisualize, 0) animated:YES];
	}
}
- (void)submit:(dfhgwhruebvhrheyleisureinterference *)model {
	[dfhgwhruebvhrheyoptionsaving.keyWindow startLoading];
	__weak typeof(self) weakSelf = self;
	NSDictionary *params = [model yy_modelToJSONObject];
	[[dfhgwhruebvhrheyluggagerecorder shareInstance] dhgfywegwygeydwbarrierawait:dhgfywegwygeydwawaitlamb path:feedbackApi isEncrypt:YES withParams:params success:^(NSURLSessionDataTask * _Nonnull task, NSString * _Nonnull json) {
		[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
		__strong typeof(weakSelf) strongSelf = weakSelf;
		dfhgwhruebvhrheysternideology *res = [dfhgwhruebvhrheysternideology yy_modelWithJSON:json];
		if (res.code == 200) {
			if ([model.type isEqualToString:@"1"]) {
				[strongSelf.productVC clean];
			}else {
				[strongSelf.collectionVC clean];
			}
			[dfhgwhruebvhrheyoptionsaving.keyWindow show:@"Feedback Success"];
		}else {
			[dfhgwhruebvhrheyoptionsaving.keyWindow show:res.error];
		}
	} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
		[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
	}];
}
- (void)viewDidLayoutSubviews {
	[super viewDidLayoutSubviews];
	[spaceView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop).offset(22);
		make.left.right.equalTo(self.view);
		make.height.mas_equalTo(22);
	}];
	[productIssusBtn mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(topView).offset(13);
		make.centerY.equalTo(topView);
		make.height.mas_equalTo(40);
		make.right.equalTo(collectionIssueBtn.mas_left).offset(-10);
	}];
	[collectionIssueBtn mas_makeConstraints:^(MASConstraintMaker *make) {
		make.right.equalTo(topView).offset(-13);
		make.width.height.centerY.equalTo(productIssusBtn);
	}];
	[lineIV mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(topView).offset((dhgfywegwygeydwdispositionvisualize/2 - 20)/2).priorityMedium();
		make.size.mas_offset(CGSizeMake(20, 3));
		make.bottom.equalTo(topView).offset(-10);
	}];
	[topView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
		make.left.right.equalTo(self.view);
		make.height.mas_equalTo(54);
	}];
	[scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(topView.mas_bottom);
		make.left.bottom.right.equalTo(self.view);
	}];
	[containerView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.edges.equalTo(scrollView);
		make.height.equalTo(scrollView);
	}];
	[self.productVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.left.bottom.equalTo(containerView);
		make.width.mas_equalTo(dhgfywegwygeydwdispositionvisualize);
	}];
	[self.collectionVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self.productVC.view.mas_right);
		make.top.bottom.right.equalTo(containerView);
		make.width.equalTo(self.productVC.view);
	}];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
	[lineIV mas_updateConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(topView).offset((dhgfywegwygeydwdispositionvisualize/2 - 20)/2 + scrollView.contentOffset.x/2);
	}];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
	int tag = scrollView.contentOffset.x == 0 ? 100 : 101;
	UIButton *sender = [topView viewWithTag:tag];
	[self topBtnsAction:sender];
}
@end
